out vec4 FragColor;
 
in vec3 fragUv;

#ifndef USE_CUBEMAP

uniform sampler2D skybox;

const vec2 invAtan = vec2(0.1591,0.3183);
vec2 sampleSphericalMap(vec3 v){
    vec2 uv = vec2(atan(v.z,v.x),asin(v.y));
    uv *= invAtan;
    uv += 0.5;
    return uv;
}

void main(){
    vec2 uv = sampleSphericalMap(normalize(fragUv));
    FragColor = texture(skybox, uv);    
}
#else

uniform samplerCube skybox;
void main()
{    
    FragColor = texture(skybox, fragUv);
}
#endif